package cn.jasonone.tio.tcp.handler.impl;

import cn.hutool.core.util.SerializeUtil;
import cn.jasonone.tio.tcp.handler.SerializationHandler;
import cn.jasonone.tio.tcp.model.Header;

import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @author xujie
 * @version 1.0
 * @date 2022/1/19 8:10
 */
public class JdkSerializationHandler implements SerializationHandler<Serializable> {
    @Override
    public byte[] serialize(Header header, Map<String, Object> context, Serializable obj, Charset charset) {
        return SerializeUtil.serialize(obj);
    }

    @Override
    public Serializable deserialize(Header header, Map<String, Object> context, byte[] bytes, Charset charset) {
        return SerializeUtil.deserialize(bytes);
    }
}
